import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/foundation.dart';
import 'package:mobile_app.core/core/domain/config/config.dart';

class Crashlytics {
  const Crashlytics._internal();

  static const _instance = Crashlytics._internal();

  factory Crashlytics() {
    return _instance;
  }

  Future<void> initialize() async {
    await FirebaseCrashlytics.instance
        .setCrashlyticsCollectionEnabled(Config().crashReportsEnabled);
  }

  void recordFlutterFatalError(FlutterErrorDetails flutterErrorDetails) {
    FirebaseCrashlytics.instance.recordFlutterFatalError(flutterErrorDetails);
  }

  void recordError({
    dynamic error,
    StackTrace? stackTrace,
    bool fatal = false,
  }) {
    FirebaseCrashlytics.instance.recordError(
      error,
      stackTrace,
      fatal: fatal,
    );
  }
}
